#ifndef XGDoubleClickEventIncluded
#define XGDoubleClickEventIncluded
#include "XueYue\Base.j"
library XGDoubleClickEvent initializer Init requires XGbase

globals
	private trigger array Trigger
	private integer Num = 0
    
    private timer Timer
	private integer array Unit
    private integer array Ts
endglobals
private function Timer_Code takes nothing returns nothing
    set Ts[99] = Ts[99] + 1
endfunction
function XG_DoubleClick_Reg takes trigger trg returns nothing
	set Num=Num+1
	set Trigger[Num]=trg
endfunction
private function Action takes nothing returns nothing
	local unit u=GetTriggerUnit()
    local integer uid = GetHandleId(u)
	local player p=GetTriggerPlayer()
	local integer i=GetPlayerId(p)
    if Unit[i] == uid and Ts[i] + 25 >= Ts[99] then
        set Unit[i] = 0
        set Ts[i] = 0
        
        set i=1
        loop
            exitwhen i>Num
            if IsTriggerEnabled(Trigger[i]) then
                if TriggerEvaluate(Trigger[i]) then
                    call TriggerExecute(Trigger[i])
                endif
            endif
            set i=i+1
        endloop
    else
        set Unit[i] = uid
        set Ts[i] = Ts[99]
    endif
    set u = null
    set p = null
endfunction
private function Init takes nothing returns nothing
	local integer i=0
    set Timer = CreateTimer()
    call TimerStart(Timer,0.01,true,function Timer_Code)
	set Trigger[0]=CreateTrigger()
	loop
        set Ts[i] = 0
		set Unit[i]=0
		call TriggerRegisterPlayerUnitEvent(Trigger[0], Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
		set i=i+1
		exitwhen i==16
	endloop
	call TriggerAddAction(Trigger[0],function Action)
endfunction
endlibrary
#endif
